#!/usr/bin/env bash
#
#

#保持nginx,mysqld,php-fpm,vod_api,vod_node一直运行
#
r_mysqld="/etc/init.d/mysqld start"
r_php1="/etc/init.d/php-fpm start"
r_php2="/usr/local/php/sbin/php-fpm -R"
if [ -f /usr/local/php/sbin/php-fpm ];then
    r_php=$r_php2
else
    r_php=$r_php1
fi
r_nginx="/etc/init.d/nginx start"
r_vod_api="/etc/init.d/vod_api start"
r_vod_node="/etc/init.d/vod_node start"
r_redis1="redis-server /usr/local/src/redis-2.8.5/redis.conf"
r_redis2="/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf"
if [ -f /usr/local/redis/etc/redis.conf ];then
    r_redis=$r_redis2
else
    r_redis=$r_redis1
fi

proc_group=(mysql nginx  vod_node.jar redis php-fpm)
r_group=("$r_mysqld" "$r_nginx" "$r_vod_node" "$r_redis" "$r_php")


n=0
for i in ${proc_group[*]}
do
    p_num=`ps axj |grep $i |grep -v grep |wc -l`
    if [ $p_num -eq 0 ];then
	eval "${r_group[$n]}"
    fi
    let n++
    sleep 3
done
